1104A - Splitting into digits - CodeForces Solution


constructive algorithms implementation math *800

Please click on ads to support us..

Python Code:

num = int(input())

maxDivisor = vezes = 0
lista = [1,2,3,4,5,6,7,8,9]

if num in lista:
    maxDivisor = num
else:
    for i in range(9,0,-1):
        if num % i == 0:
            maxDivisor = i
            break

vezes = int(num / maxDivisor)

print(vezes)

print(f"{maxDivisor} "*vezes)

C++ Code:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
void solve();

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("error.txt", "w", stderr);
  freopen("output.txt", "w", stdout);
#endif

  int t = 1;
  /*is Single Test case?*/ //cin >> t;
  while (t--)
  {
    solve();
    cout << endl;
  }

  // cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}

ll power(ll x, ll y)
{
  ll temp;
  if (y == 0)
    return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}

void SieveOfEratosthenes(int n)
{
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= n; p++)
  {

    if (prime[p] == true)
    {

      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  // Print all prime numbers
  for (int p = 2; p <= n; p++)
    if (prime[p])
      cout << p << " ";
}

// bool isContains(queue<ll> q, ll x)
// {
//   while (!q.empty())
//   {
//     if (q.front() == x)
//       return true;
//     q.pop();
//   }
//   return false;
// }

// find ka code

// if (yo.find(s) !=string::npos){
//     cout<<"YES";
// }

// hashing ka code

// unordered_map<string, int>:: iterator p;
//   for (p = wordFreq.begin();
//        p != wordFreq.end(); p++)

bool isPalindrome(string S)
{
  // Stores the reverse of the
  // string S
  string P = S;

  // Reverse the string P
  reverse(P.begin(), P.end());

  // If S is equal to P
  if (S == P)
  {
    // Return "Yes"
    return true;
  }
  // Otherwise
  else
  {
    // return "No"
    return false;
  }
}
void solve()
{
  ll n;
  cin>>n;
  for(ll i=9;i>=1;i--){
    if(n%i==0){
      cout<<n/i<<endl;
      for(ll j=0;j<n/i;j++){
        cout<<i<<" ";
      }
      return;
    }
  }
   
}


Comments

Submit
0 Comments
More Questions

Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array